home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / scripts / mkbrush.scm.z / mkbrush.scm
Encoding:
GIMP Script-Fu Script  |  1999-07-21  |  9.8 KB  |  321 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; Make-Brush - a script for the script-fu program
  5. ; by Seth Burgess 1997 <sjburges@ou.edu>
  6. ;
  7. ; This program is free software; you can redistribute it and/or modify
  8. ; it under the terms of the GNU General Public License as published by
  9. ; the Free Software Foundation; either version 2 of the License, or
  10. ; (at your option) any later version.
  11. ;
  12. ; This program is distributed in the hope that it will be useful,
  13. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ; GNU General Public License for more details.
  16. ;
  17. ; You should have received a copy of the GNU General Public License
  18. ; along with this program; if not, write to the Free Software
  19. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  
  22. (define (script-fu-make-brush-rectangular description width height spacing )
  23.     (begin
  24.         (let* (
  25.             (img (car (gimp-image-new width height GRAY)))
  26.              (drawable (car (gimp-layer-new img width height GRAY_IMAGE "MakeBrush" 100 NORMAL)))
  27.  
  28.      ; Save old foregound and background colors
  29.  
  30.      (old-fg-color (car (gimp-palette-get-foreground)))
  31.      (old-bg-color (car (gimp-palette-get-background)))
  32.  
  33.      ; construct variables 
  34.  
  35.      (data-dir (car (gimp-gimprc-query "gimp_dir"))) 
  36.      (filename (string-append data-dir
  37.                "/brushes/r" 
  38.                (number->string width) 
  39.                "x" 
  40.                (number->string height) 
  41.                ".gbr")
  42.                )
  43.      (desc (string-append description " " 
  44.                   (number->string width) 
  45.                   "x" 
  46.                   (number->string height)
  47.                   )
  48.       )
  49.     )
  50.  
  51.     (gimp-image-disable-undo img)
  52.     (gimp-image-add-layer img drawable 0)
  53.  
  54. ; Actual code starts...
  55.     (gimp-palette-set-background '(0 0 0))
  56.     (gimp-drawable-fill drawable BG-IMAGE-FILL)
  57.     (gimp-palette-set-background '(255 255 255))
  58.     (gimp-rect-select img 0 0 width height REPLACE FALSE 0)
  59.     
  60.     (gimp-edit-fill    img drawable) 
  61.     (file-gbr-save 1 img drawable filename "" spacing desc)
  62.     
  63.     (gimp-brushes-refresh) 
  64.     (gimp-brushes-set-brush desc)
  65.  
  66. ; Terminate, restoring old bg.
  67.  
  68.     (gimp-selection-none img)
  69.     (gimp-palette-set-foreground old-fg-color)
  70.     (gimp-palette-set-background old-bg-color)
  71.     (gimp-image-enable-undo img)
  72.     (gimp-image-delete img)
  73.     )
  74.   )
  75.  
  76. ; Register with the PDB
  77.  
  78. (script-fu-register "script-fu-make-brush-rectangular"
  79.             "<Toolbox>/Xtns/Script-Fu/Make Brush/Rectangular"
  80.             "Create size of brush"
  81.             "Seth Burgess <sjburges@ou.edu>"
  82.             "Seth Burgess"
  83.             "1997"
  84.             ""
  85.             SF-VALUE "Description" "\"Rectangle\""
  86.             SF-VALUE "Width" "20"
  87.             SF-VALUE "Height" "20"
  88.             SF-VALUE "Spacing" "20"
  89.             )
  90.  
  91.  
  92. (define (script-fu-make-brush-rectangular-feathered description width height feathering spacing)
  93.     (begin
  94.         (let* (
  95.             (widthplus (+ width feathering))
  96.             (heightplus (+ height feathering))
  97.             (img (car (gimp-image-new widthplus heightplus GRAY)))
  98.              (drawable (car (gimp-layer-new img widthplus heightplus GRAY_IMAGE "MakeBrush" 100 NORMAL)))
  99.  
  100.      ; Save old foregound and background colors
  101.  
  102.      (old-fg-color (car (gimp-palette-get-foreground)))
  103.      (old-bg-color (car (gimp-palette-get-background)))
  104.      
  105.     (data-dir (car (gimp-gimprc-query "gimp_dir"))) 
  106.     (filename (string-append data-dir
  107.                "/brushes/r" 
  108.                (number->string width) 
  109.                "x" 
  110.                (number->string height) 
  111.                "f"
  112.                (number->string feathering)
  113.                ".gbr")
  114.                )
  115.      (desc (string-append description " " 
  116.                   (number->string width) 
  117.                   "x" 
  118.                   (number->string height)
  119.                   ","
  120.                   (number->string feathering)
  121.                   )
  122.       )
  123.     )
  124.  
  125.     (gimp-image-disable-undo img)
  126.     (gimp-image-add-layer img drawable 0)
  127.  
  128. ; Actual code starts...
  129.     (gimp-palette-set-background '(0 0 0))
  130.     (gimp-drawable-fill drawable BG-IMAGE-FILL)
  131.     (gimp-palette-set-background '(255 255 255))
  132.     (cond ((< 0 feathering) 
  133.            (gimp-rect-select img (/ feathering 2) (/ feathering 2) width height REPLACE TRUE feathering))
  134.           ((>= 0 feathering)
  135.            (gimp-rect-select img 0 0 width height REPLACE FALSE 0))
  136.           )
  137.     (gimp-edit-fill    img drawable) 
  138.     (file-gbr-save 1 img drawable filename "" 25 desc)
  139.     
  140.     (gimp-brushes-refresh) 
  141.     (gimp-brushes-set-brush desc)
  142.  
  143. ; Terminate, restoring old bg.
  144.  
  145.     (gimp-selection-none img)
  146.     (gimp-palette-set-foreground old-fg-color)
  147.     (gimp-palette-set-background old-bg-color)
  148.     (gimp-image-enable-undo img)
  149.     (gimp-image-delete img)
  150.     )
  151.   )
  152.  
  153. ; Register with the PDB
  154.  
  155. (script-fu-register "script-fu-make-brush-rectangular-feathered"
  156.             "<Toolbox>/Xtns/Script-Fu/Make Brush/Rectangular, Feathered"
  157.             "Create size of brush"
  158.             "Seth Burgess <sjburges@ou.edu>"
  159.             "Seth Burgess"
  160.             "1997"
  161.             ""
  162.             SF-VALUE "Description" "\"Rectangle\""
  163.             SF-VALUE "Width" "20"
  164.             SF-VALUE "Height" "20"
  165.             SF-VALUE "Feathering" "4"
  166.             SF-VALUE "Spacing" "25" 
  167.             )
  168.  
  169. (define (script-fu-make-brush-elliptical description width height spacing)
  170.     (begin
  171.         (let* (
  172.             (img (car (gimp-image-new width height GRAY)))
  173.              (drawable (car (gimp-layer-new img width height GRAY_IMAGE "MakeBrush" 100 NORMAL)))
  174.  
  175.      ; Save old foregound and background colors
  176.  
  177.      (old-fg-color (car (gimp-palette-get-foreground)))
  178.      (old-bg-color (car (gimp-palette-get-background)))
  179.  
  180.      ; Construct variables...
  181.  
  182.      (data-dir (car (gimp-gimprc-query "gimp_dir")))
  183.      (filename (string-append data-dir
  184.                   "/brushes/e" 
  185.                   (number->string width) 
  186.                   "x" 
  187.                   (number->string height) 
  188.                   ".gbr"))
  189.      (desc (string-append description " " 
  190.               (number->string width) 
  191.               "x" 
  192.               (number->string height)
  193.               )
  194.        )
  195.      )
  196.       ; End of variables.  Couple of necessary things here.
  197.  
  198.     (gimp-image-disable-undo img)
  199.     (gimp-image-add-layer img drawable 0)
  200.  
  201. ; Actual code starts...
  202.     (gimp-palette-set-background '(0 0 0))
  203.     (gimp-drawable-fill drawable BG-IMAGE-FILL)
  204.     (gimp-palette-set-background '(255 255 255))
  205.     (gimp-ellipse-select img 0 0 width height REPLACE TRUE FALSE 0)
  206.     
  207.     (gimp-edit-fill    img drawable) 
  208.     (file-gbr-save 1 img drawable filename "" spacing desc)
  209.     
  210.     (gimp-brushes-refresh) 
  211.     (gimp-brushes-set-brush desc)
  212.  
  213. ; Terminate, restoring old bg.
  214.  
  215.     (gimp-selection-none img)
  216.     (gimp-palette-set-foreground old-fg-color)
  217.     (gimp-palette-set-background old-bg-color)
  218.     (gimp-image-enable-undo img)
  219.     (gimp-image-delete img)
  220.     )
  221.   )
  222.  
  223. ; Register with the PDB
  224.  
  225. (script-fu-register "script-fu-make-brush-elliptical"
  226.             "<Toolbox>/Xtns/Script-Fu/Make Brush/Elliptical"
  227.             "Create size of brush"
  228.             "Seth Burgess <sjburges@ou.edu>"
  229.             "Seth Burgess"
  230.             "1997"
  231.             ""
  232.             SF-VALUE "Description" "\"Ellipse\""
  233.             SF-VALUE "Width" "20"
  234.             SF-VALUE "Height" "20"
  235.             SF-VALUE "Spacing" "25"
  236.             )
  237.  
  238.  
  239. (define (script-fu-make-brush-elliptical-feathered description width height feathering spacing)
  240.     (begin
  241.         (let* (
  242.         (widthplus (+ feathering width)) ; add 3 for blurring
  243.             (heightplus (+ feathering height))
  244.             (img (car (gimp-image-new widthplus heightplus GRAY)))
  245.              (drawable (car (gimp-layer-new img widthplus heightplus GRAY_IMAGE "MakeBrush" 100 NORMAL)))
  246.  
  247.      ; Save old foregound and background colors
  248.  
  249.      (old-fg-color (car (gimp-palette-get-foreground)))
  250.      (old-bg-color (car (gimp-palette-get-background)))
  251.  
  252.      ; Construct variables...
  253.      (data-dir (car (gimp-gimprc-query "gimp_dir")))
  254.      (filename (string-append data-dir
  255.                   "/brushes/e" 
  256.                   (number->string width) 
  257.                   "x" 
  258.                   (number->string height) 
  259.                   "f"
  260.                   (number->string feathering)
  261.                   ".gbr"))
  262.      (desc (string-append description " " 
  263.               (number->string width) 
  264.               "x" 
  265.               (number->string height)
  266.               " f"
  267.               (number->string feathering)
  268.               )
  269.        )
  270.      
  271.      )
  272. ; End of variables.  Couple of necessary things here.
  273.  
  274.     (gimp-image-disable-undo img)
  275.     (gimp-image-add-layer img drawable 0)
  276.  
  277. ; Actual code starts...
  278.     (gimp-palette-set-background '(0 0 0))
  279.     (gimp-drawable-fill drawable BG-IMAGE-FILL)
  280.     (gimp-palette-set-background '(255 255 255))
  281.     (cond ((> feathering 0)   ; keep from taking out gimp with stupid entry. 
  282.         (gimp-ellipse-select img (/ feathering 2) (/ feathering 2) width height REPLACE TRUE TRUE feathering))
  283.           ((<= feathering 0) 
  284.         (gimp-ellipse-select img 0 0 width height REPLACE TRUE FALSE 0)) 
  285.     )
  286.     (gimp-edit-fill    img drawable) 
  287.     (file-gbr-save 1 img drawable filename "" spacing desc)
  288.     
  289.     (gimp-brushes-refresh) 
  290.     (gimp-brushes-set-brush desc)
  291.  
  292. ; Terminate, restoring old bg.
  293.  
  294.     (gimp-selection-none img)
  295.     (gimp-palette-set-foreground old-fg-color)
  296.     (gimp-palette-set-background old-bg-color)
  297.     (gimp-image-enable-undo img)
  298.     (gimp-image-delete img)
  299.     )
  300.   )
  301.  
  302. ; Register with the PDB
  303.  
  304. (script-fu-register "script-fu-make-brush-elliptical-feathered"
  305.             "<Toolbox>/Xtns/Script-Fu/Make Brush/Elliptical, Feathered"
  306.             "Create size of brush"
  307.             "Seth Burgess <sjburges@ou.edu>"
  308.             "Seth Burgess"
  309.             "1997"
  310.             ""
  311.             SF-VALUE "Description" "\"Ellipse\""
  312.             SF-VALUE "Width" "20"
  313.             SF-VALUE "Height" "20"
  314.             SF-VALUE "Feathering" "4"
  315.             SF-VALUE "Spacing" "25"
  316.             )
  317.